package com.coders.android.util.validation;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Validar email a partir de expresiones regulares
 * 
 * @author Juan & Jaime
 * @version 0.1
 * 
 * l1nux.deb14n@gmail.com & betoskap84@gmail.com
 *
 */
public class EmailValidator {
 
	private Pattern pattern;
	private Matcher matcher;
 
	private static final String EMAIL_PATTERN = 
		"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
		+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
 
	public EmailValidator() {
		pattern = Pattern.compile(EMAIL_PATTERN);
	}
 
	/**
	 * Validate mail with regular expression
	 * 
	 * @param mail for validation
	 * @return true valid mail, false invalid mail
	 */
	public boolean validate(final String mail) {
 
		matcher = pattern.matcher(mail);
		return matcher.matches();
	}
}
